
func int B_SelectSpell(var C_Npc slf,var C_Npc oth)
{
	var int dK_rnd;
	var int dK_Mega;
	var int spellvar;
	var string str;
	var string str2;
	var int CurrentChance;
	if((Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1212_dagot)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1213_morius)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1214_tegon)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1215_kelios)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1216_demos)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1217_farion)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1218_gader)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1219_narus)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1220_wakon)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1297_stonnos)))
	{
		if(Npc_HasItems(slf,itru_teleportdagot) == 0)
		{
			CreateInvItems(slf,itru_teleportdagot,1);
		};
		if((Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1212_dagot)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1213_morius)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1214_tegon)))
		{
			if(Npc_HasItems(slf,ItRu_Skull) == 0)
			{
				CreateInvItems(slf,ItRu_Skull,1);
			};
			if(C_NpcHasAttackReasonToKill(slf))
			{
				B_ReadySpell(slf,SPL_Skull,SPL_Cost_Skull);
				return TRUE;
			}
			else
			{
				B_ReadySpell(slf,SPL_TELEPORTDAGOT,SPL_Cost_Teleport);
				return TRUE;
			};
		}
		else if((Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1215_kelios)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1216_demos)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1217_farion)))
		{
			if(Npc_HasItems(slf,ItRu_Pyrokinesis) == 0)
			{
				CreateInvItems(slf,ItRu_Pyrokinesis,1);
			};
			if(C_NpcHasAttackReasonToKill(slf))
			{
				B_ReadySpell(slf,SPL_Pyrokinesis,SPL_COST_Firestorm);
				return TRUE;
			}
			else
			{
				B_ReadySpell(slf,SPL_TELEPORTDAGOT,SPL_Cost_Teleport);
				return TRUE;
			};
		}
		else if((Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1218_gader)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1219_narus)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1220_wakon)))
		{
			if(Npc_HasItems(slf,ItRu_LightningFlash) == 0)
			{
				CreateInvItems(slf,ItRu_LightningFlash,1);
			};
			if(C_NpcHasAttackReasonToKill(slf))
			{
				B_ReadySpell(slf,SPL_LightningFlash,SPL_Cost_LightningFlash);
				return TRUE;
			}
			else
			{
				B_ReadySpell(slf,SPL_TELEPORTDAGOT,SPL_Cost_Teleport);
				return TRUE;
			};
		}
		else if(Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_1297_stonnos))
		{
			if(Npc_HasItems(slf,ItRu_Whirlwind) == 0)
			{
				CreateInvItems(slf,ItRu_Whirlwind,1);
			};
			if(C_NpcHasAttackReasonToKill(slf))
			{
				B_ReadySpell(slf,SPL_Whirlwind,SPL_Cost_Whirlwind);
				return TRUE;
			}
			else
			{
				B_ReadySpell(slf,SPL_TELEPORTDAGOT,SPL_Cost_Teleport);
				return TRUE;
			};
		};
	};
	if((Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12120_dagot)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12130_morius)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12140_tegon)))
	{
		if(Npc_HasItems(slf,ItRu_Skull) == 0)
		{
			CreateInvItems(slf,ItRu_Skull,1);
		};
		B_ReadySpell(slf,SPL_Skull,SPL_Cost_Skull);
		return TRUE;
	}
	else if((Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12150_kelios)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12160_demos)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12170_farion)))
	{
		if(Npc_HasItems(slf,ItRu_Pyrokinesis) == 0)
		{
			CreateInvItems(slf,ItRu_Pyrokinesis,1);
		};
		B_ReadySpell(slf,SPL_Pyrokinesis,SPL_COST_Firestorm);
		return TRUE;
	}
	else if((Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12180_gader)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12190_narus)) || (Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12200_wakon)))
	{
		if(Npc_HasItems(slf,ItRu_LightningFlash) == 0)
		{
			CreateInvItems(slf,ItRu_LightningFlash,1);
		};
		B_ReadySpell(slf,SPL_LightningFlash,SPL_Cost_LightningFlash);
		return TRUE;
	}
	else if(Hlp_GetInstanceID(self) == Hlp_GetInstanceID(dmt_12970_stonnos))
	{
		if(Npc_HasItems(slf,ItRu_Whirlwind) == 0)
		{
			CreateInvItems(slf,ItRu_Whirlwind,1);
		};
		B_ReadySpell(slf,SPL_Whirlwind,SPL_Cost_Whirlwind);
		return TRUE;
	};
	if(slf.guild == GIL_GUR)
	{
		if(RUNEMAGICNOTWORK == TRUE)
		{
			return FALSE;
		};
		if(Npc_HasItems(slf,ItRu_Whirlwind) == 0)
		{
			CreateInvItems(slf,ItRu_Whirlwind,1);
		};
		if(Npc_HasItems(slf,ItRu_Sleep) == 0)
		{
			CreateInvItems(slf,ItRu_Sleep,1);
		};
		if(Npc_HasItems(slf,ItRu_FullHeal) == 0)
		{
			CreateInvItems(slf,ItRu_FullHeal,1);
		};
		if(slf.attribute[ATR_HITPOINTS] < 200)
		{
			B_ReadySpell(slf,SPL_FullHeal,SPL_Cost_FullHeal);
			return TRUE;
		};
		if(C_NpcHasAttackReasonToKill(slf))
		{
			B_ReadySpell(slf,SPL_Whirlwind,SPL_Cost_Whirlwind);
			return TRUE;
		}
		else if(oth.guild >= 24)
		{
			B_ReadySpell(slf,SPL_Whirlwind,SPL_Cost_Whirlwind);
			return TRUE;
		}
		else
		{
			B_ReadySpell(slf,SPL_Sleep,SPL_Cost_Sleep);
			return TRUE;
		};
	};
	if((Hlp_GetInstanceID(slf) == Hlp_GetInstanceID(NONE_100_Xardas)) || (Hlp_GetInstanceID(slf) == Hlp_GetInstanceID(none_102_kreol)))
	{
		if(RUNEMAGICNOTWORK == TRUE)
		{
			return FALSE;
		};
		if(Npc_HasItems(slf,ItRu_Skull) == 0)
		{
			CreateInvItems(slf,ItRu_Skull,1);
		};
		if(Npc_HasItems(slf,ItRu_FullHeal) == 0)
		{
			CreateInvItems(slf,ItRu_FullHeal,1);
		};
		if(slf.attribute[ATR_HITPOINTS] < 200)
		{
			B_ReadySpell(slf,SPL_FullHeal,SPL_Cost_FullHeal);
			return TRUE;
		}
		else
		{
			B_ReadySpell(slf,SPL_Skull,SPL_Cost_Skull);
			return TRUE;
		};
	};
	if(slf.guild == GIL_DMT)
	{
		if(slf.flags == NPC_FLAG_XARADRIM)
		{
			return FALSE;
		};
		if(Hlp_GetInstanceID(slf) == Hlp_GetInstanceID(dmt_1298_darkmage))
		{
			if(Npc_HasItems(slf,ItRu_Skull) == 0)
			{
				CreateInvItems(slf,ItRu_Skull,1);
			};
			B_ReadySpell(slf,SPL_Skull,SPL_Cost_Skull);
			return TRUE;
		};
		if(Hlp_GetInstanceID(slf) == Hlp_GetInstanceID(none_117_nergal))
		{
			if(Npc_HasItems(slf,ItRu_Skull) == 0)
			{
				CreateInvItems(slf,ItRu_Skull,1);
			};
			B_ReadySpell(slf,SPL_Skull,SPL_Cost_Skull);
			return TRUE;
		};
		if(Hlp_GetInstanceID(slf) == Hlp_GetInstanceID(DMT_1299_OberDementor_DI))
		{
			if(Npc_HasItems(slf,ItRu_Skull) == 0)
			{
				CreateInvItems(slf,ItRu_Skull,1);
			};
			B_ReadySpell(slf,SPL_Skull,SPL_Cost_Skull);
			return TRUE;
		}
		else
		{
			if(Npc_IsDrawingWeapon(slf))
			{
				return TRUE;
			};
			if(Npc_HasItems(slf,ItRu_SumSkel) == 0)
			{
				CreateInvItems(slf,ItRu_SumSkel,1);
			};
			if(Npc_HasItems(slf,ItRu_Deathball) == 0)
			{
				CreateInvItems(slf,ItRu_Deathball,1);
			};
			if(slf.aivar[AIV_SelectSpell] >= 12)
			{
				slf.aivar[AIV_SelectSpell] = 0;
			};
			spellvar = slf.aivar[AIV_SelectSpell];
			if(spellvar >= 6)
			{
				spellvar = spellvar - 5;
			};
			if((spellvar == 1) || (spellvar == 3))
			{
				B_ReadySpell(slf,SPL_SummonSkeleton,SPL_Cost_SummonSkeleton);
				return TRUE;
			}
			else
			{
				B_ReadySpell(slf,SPL_Deathball,SPL_COST_Deathball);
				return TRUE;
			};
		};
	};
	if(slf.guild == GIL_KDF)
	{
		if(RUNEMAGICNOTWORK == TRUE)
		{
			return FALSE;
		};
		if(Npc_HasItems(slf,ItRu_Firestorm) == 0)
		{
			CreateInvItems(slf,ItRu_Firestorm,1);
		};
		if(Npc_HasItems(slf,ItRu_Concussionbolt) == 0)
		{
			CreateInvItems(slf,ItRu_Concussionbolt,1);
		};
		if(Npc_HasItems(slf,ItRu_FullHeal) == 0)
		{
			CreateInvItems(slf,ItRu_FullHeal,1);
		};
		if(Hlp_GetInstanceID(self) == Hlp_GetInstanceID(KDF_500_Pyrokar))
		{
			if(Npc_HasItems(slf,ItRu_TeleportMonastery) == 0)
			{
				CreateInvItems(slf,ItRu_TeleportMonastery,1);
			};
			if((KAPITELORCATC == TRUE) && (PYROKARUSEONCE == FALSE))
			{
				B_ReadySpell(slf,SPL_TeleportMonastery,SPL_Cost_Teleport);
				return TRUE;
			};
		};
		if(slf.attribute[ATR_HITPOINTS] < 200)
		{
			B_ReadySpell(slf,SPL_FullHeal,SPL_Cost_FullHeal);
			return TRUE;
		};
		if(C_NpcHasAttackReasonToKill(slf))
		{
			B_ReadySpell(slf,SPL_Firestorm,SPL_Cost_InstantFireStorm);
			return TRUE;
		}
		else if(oth.guild >= 24)
		{
			B_ReadySpell(slf,SPL_Firestorm,SPL_Cost_InstantFireStorm);
			return TRUE;
		}
		else
		{
			B_ReadySpell(slf,SPL_ConcussionBolt,SPL_COST_Concussionbolt);
			return TRUE;
		};
	};
	if(slf.guild == GIL_KDW)
	{
		if(RUNEMAGICNOTWORK == TRUE)
		{
			return FALSE;
		};
		if(Npc_HasItems(slf,ItRu_LightningFlash) == 0)
		{
			CreateInvItems(slf,ItRu_LightningFlash,1);
		};
		if(Npc_HasItems(slf,ItRu_Concussionbolt) == 0)
		{
			CreateInvItems(slf,ItRu_Concussionbolt,1);
		};
		if(Npc_HasItems(slf,ItRu_FullHeal) == 0)
		{
			CreateInvItems(slf,ItRu_FullHeal,1);
		};
		if(slf.attribute[ATR_HITPOINTS] < 200)
		{
			B_ReadySpell(slf,SPL_FullHeal,SPL_Cost_FullHeal);
			return TRUE;
		};
		if(C_NpcHasAttackReasonToKill(slf))
		{
			B_ReadySpell(slf,SPL_LightningFlash,SPL_Cost_LightningFlash);
			return TRUE;
		}
		else if(oth.guild >= 24)
		{
			B_ReadySpell(slf,SPL_LightningFlash,SPL_Cost_LightningFlash);
			return TRUE;
		}
		else
		{
			B_ReadySpell(slf,SPL_ConcussionBolt,SPL_COST_Concussionbolt);
			return TRUE;
		};
	};
	if(slf.guild == GIL_PAL)
	{
		if(RUNEMAGICNOTWORK == TRUE)
		{
			return FALSE;
		};
		if(slf.fight_tactic == FAI_NAILED)
		{
			return FALSE;
		};
		if(Npc_HasItems(slf,ItRu_PalHolyBolt) == 0)
		{
			CreateInvItems(slf,ItRu_PalHolyBolt,1);
		};
		if(Npc_HasItems(slf,ItRu_PalFullHeal) == 0)
		{
			CreateInvItems(slf,ItRu_PalFullHeal,1);
		};
		if(slf.attribute[ATR_HITPOINTS] < 200)
		{
			B_ReadySpell(slf,SPL_PalFullHeal,SPL_Cost_PalFullHeal);
			return TRUE;
		};
		if((Npc_GetDistToNpc(slf,oth) > FIGHT_DIST_MELEE) && C_NpcIsEvil(oth))
		{
			B_ReadySpell(slf,SPL_PalHolyBolt,SPL_Cost_PalHolyBolt);
			return TRUE;
		}
		else
		{
			return FALSE;
		};
	};
	if(Hlp_GetInstanceID(slf) == Hlp_GetInstanceID(vlk_6027_taliasan))
	{
		if(RUNEMAGICNOTWORK == TRUE)
		{
			return FALSE;
		};
		if(Npc_HasItems(slf,ItRu_Concussionbolt) == 0)
		{
			CreateInvItems(slf,ItRu_Concussionbolt,1);
		};
		if(Npc_HasItems(slf,ItRu_FullHeal) == 0)
		{
			CreateInvItems(slf,ItRu_FullHeal,1);
		};
		if(slf.attribute[ATR_HITPOINTS] < 200)
		{
			B_ReadySpell(slf,SPL_FullHeal,SPL_Cost_FullHeal);
			return TRUE;
		};
		if(C_NpcHasAttackReasonToKill(slf))
		{
			B_ReadySpell(slf,SPL_ConcussionBolt,SPL_COST_Concussionbolt);
			return TRUE;
		}
		else
		{
			B_ReadySpell(slf,SPL_ConcussionBolt,SPL_COST_Concussionbolt);
			return TRUE;
		};
	};
	if(slf.aivar[AIV_MM_REAL_ID] == ID_SKELETON_MAGE)
	{
		if(Npc_HasItems(slf,ItRu_Deathball) == 0)
		{
			CreateInvItems(slf,ItRu_Deathball,1);
		};
		if(Npc_HasItems(slf,ItRu_SumSkel) == 0)
		{
			CreateInvItems(slf,ItRu_SumSkel,1);
		};
		if(slf.aivar[AIV_SelectSpell] >= 12)
		{
			slf.aivar[AIV_SelectSpell] = 0;
		};
		spellvar = slf.aivar[AIV_SelectSpell];
		if(spellvar >= 6)
		{
			spellvar = spellvar - 5;
		};
		if((spellvar == 1) || (spellvar == 3))
		{
			B_ReadySpell(slf,SPL_SummonSkeleton,SPL_Cost_SummonSkeleton);
			return TRUE;
		}
		else
		{
			B_ReadySpell(slf,SPL_Deathball,SPL_COST_Deathball);
			return TRUE;
		};
	};
	if(slf.aivar[AIV_MM_REAL_ID] == ID_ORCSHAMAN)
	{
		if(Npc_HasItems(slf,itmw_orcstaff_elite) > 0)
		{
			if(Npc_HasItems(slf,ItRu_Pyrokinesis) == 0)
			{
				CreateInvItems(slf,ItRu_Pyrokinesis,1);
			};
			if(Npc_HasItems(slf,ItRu_Pyrokinesis) > 0)
			{
				B_ReadySpell(slf,SPL_Pyrokinesis,SPL_COST_Firestorm);
				return TRUE;
			}
			else
			{
				return FALSE;
			};
		}
		else
		{
			if(Npc_HasItems(slf,ItRu_ChargeFireball) == 0)
			{
				CreateInvItems(slf,ItRu_ChargeFireball,1);
			};
			if(Npc_HasItems(slf,ItRu_ChargeFireball) > 0)
			{
				B_ReadySpell(slf,SPL_ChargeFireball,SPL_COST_ChargeFireball);
				return TRUE;
			}
			else
			{
				return FALSE;
			};
		};
	};
	if(slf.aivar[AIV_MM_REAL_ID] == ID_UNDEADORCSHAMAN)
	{
		if(Npc_HasItems(slf,ItRu_MassDeath) == 0)
		{
			CreateInvItems(slf,ItRu_MassDeath,1);
		};
		if(Npc_HasItems(slf,ItRu_MassDeath) > 0)
		{
			B_ReadySpell(slf,SPL_BreathOfDeath,SPL_Cost_MassDeath);
			return TRUE;
		}
		else
		{
			return FALSE;
		};
	};
	return FALSE;
};

